#include <QCoreApplication>
#include "simpleplugin.h"

SimplePlugin::SimplePlugin()
{
    printf("Constructor of SimplePlugin\n");
}

SimplePlugin::~SimplePlugin()
{
    printf("Destructor of SimplePlugin\n");
}

DictionaryDescription SimplePlugin::getDescription()
{
    DictionaryDescription d;
    d.setName("Full name of example plugin");
    d.setShortName("Example plugin");
    d.setIcon(QIcon(":/icon.png"));
    d.setAbout("<span style=\"color = red;\">about of example plugin</span>");
    //below infos current un-used.
    d.setFromLang(DictionaryDescription::English);
    d.setToLang(DictionaryDescription::English);
    d.setVersion("1.0");
    return d;
}

QList<QPair<QString, QString> > SimplePlugin::getCandidateWords(QString key)
{
    QList<QPair<QString, QString> > wordsList;

    for(int i = 0; i < 100; i++) {
        QString keyword = key + QString("%1").arg(i);
        QString displayword = key + QString("-%1").arg(i);
        if(filterBtn && filterBtn->isChecked()) {
            keyword = keyword.toUpper();
            displayword = displayword.toUpper();
        }
        wordsList.append(QPair<QString, QString>(keyword, displayword));
    }
    return wordsList;
}


void SimplePlugin::queryWord(QString key)
{

    QString result = QString("<html><body style=\"font-size:14pt\">")
                   + "<p>what your input is <b>\""+key + "\"</b></p>"
                   + "<a href=\"tooltiptest1://abc\">this is tooltip1</a>";

    if(filterBtn && filterBtn->isChecked())
        result += "<p>After filter, key is:<b>" + key.toUpper() + "</b></p>";

    result += "</body></html>";
    emit readyToShow(result);
}

QWidget * SimplePlugin::getToolbarFilterWidget()
{
   filterBtn = new QPushButton("to Upper");
   filterBtn->setCheckable(true);
   connect(filterBtn, SIGNAL(toggled(bool)), this, SIGNAL(filterChanged()));
   return filterBtn; 
}

QString SimplePlugin::getTooltip(QString protocol, QString key)
{
    if(protocol == "tooltiptest1") {
        if(key == "abc")
            return "you clicked abc";
    }
    if(protocol == "tooltiptest2") {
        if(key == "test")
            return "you clicked tooltiptest2 and key is test";
    }
    return QString();
}

QString SimplePlugin::getListFontName()
{
    return QString();
}

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#else
Q_EXPORT_PLUGIN2(simpleplugin, SimplePlugin);
#endif
